//
//  MainTabBarController.m
//  
//
//  Created by leonardo on 15/10/13.
//
//

#import "MainTabBarController.h"
#import "BaseViewController.h"
@interface MainTabBarController ()

@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSArray * arrViewControllerNames = @[@"SearchViewController",@"PreCompareViewController",@"UpdateViewController",@"NewsViewController",@"AboutUsViewController"];
    NSArray * arrViewControllerTitles = @[@"搜索资料",@"性能对比",@"升级助手",@"相关新闻",@"关于我们"];
    NSArray * arrTabbarImage = @[@"search_tabbar",@"compare_tabbar",@"update_tabbar",@"news_tabbar",@"about_tabbar"];
    NSMutableArray * arrNavis = [NSMutableArray array];
    for (int i = 0; i < arrViewControllerNames.count; i ++ ) {
        BaseViewController * vc = [NSClassFromString(arrViewControllerNames[i]) new];
        vc.title = arrViewControllerTitles[i];
       vc.tabBarItem.imageInsets = UIEdgeInsetsMake(2, 0, 0, 0);
        UIImage * img = [UIImage imageNamed:arrTabbarImage[i]];
        img = [ self reSizeImage:img toSize:CGSizeMake(40, 40)];
        [vc.tabBarItem setImage:[img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        
        UINavigationController * navi = [[UINavigationController alloc]initWithRootViewController:vc];
        
        [arrNavis addObject:navi];
    }
    
    self.viewControllers =arrNavis;
   
}
- (UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize
{
    
    UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));
    
    [image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
    
    UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    
    
    return reSizeImage;
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
